package com.qf.contorller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.pojo.Room;
import com.qf.pojo.Storage;
import com.qf.service.RoomService;
import com.qf.utils.R;
import com.qf.vo.RoomWithStorageVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zdl
 * @date 2025/2/14
 */

/**
 * 房间
 */
@RestController
@RequestMapping("/room")
public class RoomController {
    @Resource
    private RoomService roomService;

    @GetMapping("/allRoom")
    public R<PageInfo<Room>> getAllRoomByPage(@RequestParam int pageNum,@RequestParam int pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<Room> allRoom = roomService.findAllRoom();
        PageInfo<Room> roomPageInfo = new PageInfo<>(allRoom);
        return R.ok(roomPageInfo);
    }
    @PostMapping("/add")
    public R<Integer> addRoom(@RequestBody RoomWithStorageVo roomWithStorageVo){
        System.out.println(roomWithStorageVo);

        return R.ok(roomService.addRoom(roomWithStorageVo));
    }

    @PostMapping("/delBatch")
    public R<Integer> delBatchRoom(@RequestBody List<Integer> ids){
        return R.ok(roomService.delBatchRoom(ids));
    }
    @PostMapping("/update")
    public R<Integer> updateRoom(@RequestBody Room room){
        return R.ok(roomService.updateRoom(room));
    }

    /**
     * 查询全部房间 用于居住的 房间
     * @return
     */
    @GetMapping("/allUse")
    public R<List<Room>> findAllUseRoom(){
        return R.ok(roomService.findAllUseRoom());
    }

}
